//
//  AppDelegate.m
//  test2
//
//  Created by Admin on 2021/6/13.
//  Copyright © 2021年 Admin. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    [[RCIM sharedRCIM] initWithAppKey:@"bmdehs6pbf59s"];
    
    [[RCIM sharedRCIM] //connectWithToken:@"KWIb5I2A3awxFqcHfHFcrZh31jlMke98C89DvgnMQsw=@p28y.cn.rongnav.com;p28y.cn.rongcfg.com"
        connectWithToken:@"cwmZirzl6hNe66rz+3YzPdrMX4aS0BelAk2sRJI/yhM=@p28y.cn.rongnav.com;p28y.cn.rongcfg.com"
     success:^(NSString *userId) {
        NSLog(@"登陆成功。当前登录的用户ID：%@", userId);
        
        //成为当前用户信息的提供者：这个也是在你需要的地方写，我这里只是做一个提醒
        //RCUserInfo *infor = [[RCUserInfo alloc]initWithUserId:userId name:name portrait:icon];
        [RCIM sharedRCIM].userInfoDataSource = self;
        //[RCIMClient sharedRCIMClient].currentUserInfo = infor;
        
    } error:^(RCConnectErrorCode status) {
        NSLog(@"登陆的错误码为:%ld", (long)status);
    } tokenIncorrect:^{
        NSLog(@"token错误");
    }];
    
    RCCustomConversationListViewController *conversationListViewController = [[RCCustomConversationListViewController alloc] initWithDisplayConversationTypes:@[@(ConversationType_PRIVATE),@(ConversationType_GROUP),@(ConversationType_SYSTEM)] collectionConversationType:@[@(ConversationType_SYSTEM)]];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:conversationListViewController];
    self.window.rootViewController = navigationController;
    
    return YES;
}

- (void)setCurrentUserInfo {
    //设置当前用户信息，用于显示自己的头像和昵称
    RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:@"test1" name:@"左左" portrait:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1568875876191&di=2933bebe9b22899f59840c33b24a1f98&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20161119%2F7205fcb7ca4149c1920c01524112cbd9_th.jpg"];
    [RCIM sharedRCIM].currentUserInfo = userInfo;
}

// 实现用户信息提供者的代理函数
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion {
    //开发者需要将 userId 对应的用户信息返回，下列仅为示例
    if ([userId isEqualToString:@"test"]) {
        RCUserInfo *userInfo = [[RCUserInfo alloc] initWithUserId:@"youyou" name:@"右右" portrait:@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1568876149141&di=b27756a9d6c2ce32dfaf88b9f652bcf6&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201509%2F26%2F20150926151704_c3BTt.jpeg"];
        if (completion) {
            completion(userInfo);
        }
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
